package biz.obake.team.touchprotector.nolockapps;

import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import biz.obake.team.touchprotector.g.a;
import biz.obake.team.touchprotector.tpas.TPAccessibilityService;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONException;

public class b implements SharedPreferences.OnSharedPreferenceChangeListener {

    /* renamed from: c  reason: collision with root package name */
    private static b f1773c;

    /* renamed from: b  reason: collision with root package name */
    private HashMap<String, a> f1774b = new HashMap<>();

    private b() {
        c();
        e();
        a.i().registerOnSharedPreferenceChangeListener(this);
    }

    public static b b() {
        if (f1773c == null) {
            f1773c = new b();
        }
        return f1773c;
    }

    private void c() {
        PackageManager packageManager = biz.obake.team.android.a.a().getPackageManager();
        for (String str : new ArrayList(a.i().getAll().keySet())) {
            if (str.startsWith("apps_")) {
                try {
                    packageManager.getPackageInfo(str.substring(5), 0);
                } catch (PackageManager.NameNotFoundException unused) {
                    a.n(str);
                }
            }
        }
    }

    private void e() {
        for (String next : a.i().getAll().keySet()) {
            if (next.startsWith("apps_")) {
                f(next);
            }
        }
    }

    private void f(String str) {
        if (str.startsWith("apps_")) {
            String substring = str.substring(5);
            try {
                this.f1774b.put(substring, new a(a.l(str)));
            } catch (JSONException unused) {
                this.f1774b.remove(substring);
            }
        }
    }

    public a a(String str) {
        if (!TPAccessibilityService.i()) {
            return null;
        }
        return this.f1774b.get(str);
    }

    /* access modifiers changed from: package-private */
    public void d(String str, a aVar) {
        try {
            a.r("apps_" + str, aVar.a());
            f(str);
        } catch (JSONException unused) {
        }
    }

    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
        f(str);
    }
}
